package com.meet.bizservice.impl;

import com.meet.persist.dao.UserMemberLevelDao;
import com.meet.persist.dao.UserNotificationSettingsDao;
import com.meet.api.dto.response.MeetNotificationSettingsResponseDTO;
import com.meet.persist.entity.UserMemberLevel;
import com.meet.exception.BusinessException;
import com.meet.bizservice.SettingsService;
import com.meet.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SettingsServiceImpl implements SettingsService {

    private static final Logger logger = LoggerFactory.getLogger(SettingsServiceImpl.class);

    @Autowired
    private UserNotificationSettingsDao notificationSettingsDao;

    @Autowired
    private UserMemberLevelDao userMemberLevelDao;

    @Override
    public Result<MeetNotificationSettingsResponseDTO> getNotificationSettings() {

        try {
            logger.info("Getting notification settings");

            // 这里应该从JWT中获取用户ID，为简化演示直接返回示例数据
            MeetNotificationSettingsResponseDTO settings = new MeetNotificationSettingsResponseDTO();
            // 设置默认值
            settings.setMessageNotification(true);
            settings.setActivityReminder(false);
            settings.setActivityRecommendation(true);
            settings.setSystemNotification(true);
            settings.setNotificationStartHour(9);
            settings.setNotificationEndHour(21);

            return Result.success(settings);
        } catch (Exception e) {
            logger.error("Error getting notification settings", e);
            throw new BusinessException("获取通知设置失败");
        }
    }

    @Override
    public Result<Boolean> updateNotificationSettings(
            Boolean messageNotification,
            Boolean activityReminder,
            Boolean activityRecommendation,
            Boolean systemNotification,
            Integer notificationStartHour,
            Integer notificationEndHour) {

        try {
            logger.info("Updating notification settings");

            // 这里应该从JWT中获取用户ID，为简化演示直接返回成功
            return Result.success(true);
        } catch (Exception e) {
            logger.error("Error updating notification settings", e);
            throw new BusinessException("更新通知设置失败");
        }
    }

    @Override
    public Result<UserMemberLevel> getMemberLevelInfo() {

        try {
            logger.info("Getting member level info");

            // 这里应该从JWT中获取用户ID，为简化演示直接返回示例数据
            UserMemberLevel level = new UserMemberLevel();
            level.setUserId("1234567890");
            level.setLevel("premium");
            level.setPoints(1000);

            return Result.success(level);
        } catch (Exception e) {
            logger.error("Error getting member level info", e);
            throw new BusinessException("获取会员等级信息失败");
        }
    }

    @Override
    public Result<Boolean> upgradeMemberLevel(String level) {

        try {
            logger.info("Upgrading member level to: {}", level);

            // 这里应该从JWT中获取用户ID，为简化演示直接返回成功
            return Result.success(true);
        } catch (Exception e) {
            logger.error("Error upgrading member level", e);
            throw new BusinessException("升级会员等级失败");
        }
    }

}
